<template>
  <div>
    <div style="width: 100%">
      <el-input placeholder="输入编号" style="width: 250px" v-model="bnum" />
      <el-select v-model="hid" placeholder="选择医院">
        <el-option
          v-for="item in selecthospital"
          :key="item.id"
          :value="item.id"
          :label="item.hname"
        />
      </el-select>
      <el-select v-model="did" placeholder="选择科室">
        <el-option
          v-for="item in department"
          :key="item.did"
          :value="item.did"
          :label="item.dname"
        />
      </el-select>
        <el-radio-group v-model="status" >
          <el-radio label="0">空闲中</el-radio>
          <el-radio label="1">使用中</el-radio>
           <el-radio label="2">异常</el-radio>
        </el-radio-group>
      <el-button @click="getAllBeds" type="primary" icon="el-icon-search"
        >查询</el-button
      >
    </div>
    <br /><br />
    <el-table
      ref="multipleTable"
      :data="pageInfo.list"
      tooltip-effect="dark"
      style="width: 80%; margin: 0px auto"
    >
      <el-table-column
        prop="bnum"
        label="床位编号"
        width="120"
      ></el-table-column>
      <el-table-column prop="tbHospital.hname" label="医院" width="120"></el-table-column>
      <el-table-column
        prop="tbDepartment.dname"
        label="医院科室"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="type"
        label="设备型号"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="manufacturerAddress"
        label="厂家联系地址"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="manufacturerPhone"
        label="厂家联系电话"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="manufacturerContacter"
        label="厂家联系人"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="addTime"
        label="添加时间"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="status"
        label="状态"
        width="120"
      >
       <template slot-scope="scope">
    {{ scope.row.status === 0 ? '空闲中' : (scope.row.status === 1 ? '使用中' : '异常') }}
  </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[3, 5, 8, 10]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
  </div>
</template>
<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
<script>
import { getAll, getAllDepartment, getAllHospital } from "@/api/ViewBeds.js";

export default {
  data() {
    return {
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
      },
      bnum: "",
      hid: "",
      did: "",
      status: "",
      selecthospital: [],
      department: [],
    };
  },
  methods: {
    getAllBeds() {
      getAll({
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize,
        bnum: this.bnum,
        hid: this.hid,
        did: this.did,
        status: this.status,
      }).then((res) => {
        if (res.data.code == 200) {
          this.pageInfo = res.data.data;
          this.bnum = "";
          this.hid = "";
          this.did = "";
          this.status = "";
        }
      });
    },
    getDepartment() {
      getAllDepartment().then((res) => {
        if (res.data.code == 200) {
          this.department = res.data.data;
        }
      });
    },
    getHospital() {
      getAllHospital().then((res) => {
        if (res.data.code == 200) {
          this.selecthospital = res.data.data;
        }
      });
    },
    //val=改变之后的条目数
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      this.pageInfo.pageNum = 1;
      this.getAllBeds();
    },
    //改变之后的当前页
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.getAllBeds();
    },
  },
  mounted() {
    this.getAllBeds();
    this.getDepartment();
    this.getHospital();
  },
};
</script>